package dk.pun.dums.client.widget;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.Widget;

import dk.pun.dums.client.view.MainView;

public class CharacterTabWidget extends Composite {

	private static CharacterTabWidgetUiBinder uiBinder = GWT.create(CharacterTabWidgetUiBinder.class);

	interface CharacterTabWidgetUiBinder extends UiBinder<Widget, CharacterTabWidget> {
	}

	@UiField protected transient Label label;
	@UiField protected transient PushButton button;
	
	private final transient MainView mainView;
	
	public CharacterTabWidget(final String title, final MainView mainView) {
		super();
		this.initWidget(uiBinder.createAndBindUi(this));
		this.setTabTitle(title);
		this.mainView = mainView;
	}
	
	public void setTabTitle(final String title) {
		this.label.setText(title);
	}
	
	@UiHandler("button")
	public void buttonClickedHandler(final ClickEvent event) {
		this.mainView.removeCharacter(this.label.getText());
	}

}
